<?php
/**
 * Created by PhpStorm.
 * @author 清凉Tea <973110519@qq.com>
 * Date: 2018/1/20
 * Time: 16:42
 */

namespace app\api\validate;

//商品评论Post 验证器
class Comments extends BaseValidate
{
    protected $rule = [
        'order_no' => 'require',
        'comments' =>  'require|checkComments',
    ];

    protected $singleRule = [
        'pro_id' => 'require',
        'score' => 'require|in:1,2,3,4,5',
        'content' => 'require'
    ];

    public function checkComments($values)
    {
        if(!is_array($values)||empty($values))
            return false;

        foreach($values as $value){
            $validate = new BaseValidate($this->singleRule);
            if(!$validate->check($value))
                return false;
        }
        return true;
    }
}